import {
  Column,
  Entity,
  PrimaryGeneratedColumn,
  Tree,
  TreeChildren,
  TreeParent,
} from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';

@Tree('closure-table')
@Entity()
export class TreePerson {
  constructor(title = '') {
    // super();
    this.title = title;
  }
  @PrimaryGeneratedColumn()
  id: number;
  @ApiProperty({
    type: 'string',
    example: '当前节点的名称',
    description: '当前节点的名称',
  })
  @Column()
  title: string;
  @TreeChildren()
  children: TreePerson[];

  @ApiProperty({ type: 'number', example: 1, description: '父节点的id' })
  parentId?: number;

  @TreeParent()
  parent: TreePerson;
}
